﻿/// <reference path="../../scripts/typings/jquery/jquery.d.ts" />
/// <reference path="../../scripts/typings/knockout/knockout.d.ts" />
import Server = require("../../Scripts/photoweb/Server");
import Photo = require("../../Scripts/photoweb/Models/Photo");

class PhotosViewModel {
    public isLoading: KnockoutObservable<boolean>;

    constructor(public photos: KnockoutObservableArray<Photo>) {
        this.photos = ko.observableArray<Photo>();
        this.isLoading = ko.observable<boolean>(true);
    }

    public activate = (albumId: string): void => {
        this.isLoading(true);
        Server.getPhotosInAlbum(
            albumId,
            (response: Photo[]): void=> {
                this.isLoading(false);
                this.photos(response);
            },
            (err: JQueryXHR): void=> {
                this.isLoading(false);
                alert(JSON.stringify(err));
            }
            );
    };
}

export = PhotosViewModel;